<template>
  <view class="overview-container">
    <view class="header">
      <text class="title">数据概览</text>
    </view>
    
    <!-- 关键指标 -->
    <view class="metrics-section">
      <view class="metric-card">
        <text class="metric-value">{{ overviewData.totalMembers }}</text>
        <text class="metric-label">总会员数</text>
      </view>
      
      <view class="metric-card">
        <text class="metric-value">{{ overviewData.activeMembers }}</text>
        <text class="metric-label">活跃会员</text>
      </view>
      
      <view class="metric-card">
        <text class="metric-value">{{ overviewData.todayCheckins }}</text>
        <text class="metric-label">今日签到</text>
      </view>
      
      <view class="metric-card">
        <text class="metric-value">¥{{ overviewData.todayRevenue }}</text>
        <text class="metric-label">今日营收</text>
      </view>
    </view>
    
    <!-- 图表区域 -->
    <view class="charts-section">
      <view class="chart-card">
        <text class="chart-title">会员增长趋势</text>
        <view class="chart-placeholder">
          <text>会员增长图表</text>
        </view>
      </view>
      
      <view class="chart-card">
        <text class="chart-title">收入统计</text>
        <view class="chart-placeholder">
          <text>收入统计图表</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { statisticsApi } from '../../../src/services/statistics'

// 数据概览数据
const overviewData = ref({
  totalMembers: 0,
  activeMembers: 0,
  todayCheckins: 0,
  todayRevenue: 0
})

// 获取数据概览
const fetchOverview = async () => {
  try {
    const response: any = await statisticsApi.getOverview()
    if (response.code === 200) {
      overviewData.value = response.data
    }
  } catch (error) {
    console.error('获取数据概览失败:', error)
    uni.showToast({
      title: '获取数据失败',
      icon: 'error'
    })
  }
}

onMounted(() => {
  fetchOverview()
})
</script>

<style scoped>
.overview-container {
  background-color: #ffffff;
  min-height: 100vh;
  padding: 20rpx;
}

.header {
  text-align: center;
  margin-bottom: 40rpx;
  padding-top: 20rpx;
}

.title {
  font-size: 36rpx;
  font-weight: bold;
  color: #333333;
}

.metrics-section {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20rpx;
  margin-bottom: 40rpx;
}

.metric-card {
  background-color: #f8f8f8;
  border-radius: 16rpx;
  padding: 30rpx 20rpx;
  text-align: center;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
}

.metric-value {
  display: block;
  font-size: 36rpx;
  font-weight: bold;
  color: #4B0082;
  margin-bottom: 8rpx;
}

.metric-label {
  font-size: 24rpx;
  color: #666666;
}

.charts-section {
  display: flex;
  flex-direction: column;
  gap: 30rpx;
}

.chart-card {
  background-color: #f8f8f8;
  border-radius: 16rpx;
  padding: 30rpx;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
}

.chart-title {
  display: block;
  font-size: 28rpx;
  font-weight: bold;
  color: #333333;
  margin-bottom: 20rpx;
}

.chart-placeholder {
  height: 300rpx;
  background-color: #eeeeee;
  border-radius: 12rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-placeholder text {
  color: #999999;
  font-size: 28rpx;
}
</style>